<template>
	<div >
		<div class="secNavWrap">
			<div class="secNav">
				<router-link :to="{name:'channel',params:{tid:curTid}}">推荐</router-link>
				<router-link v-for="(item,index) in secondNavList":key="index" :to="{name:'channel',params:{tid:item.tid}}">
					{{item.typename}}
				</router-link>
			</div>
			
		</div>
			<div class="secContent" v-for="(item,index) in Secon">
				<p>{{item.title}}</p>
				<div class="content">
					<con :content="_handleCon(item.con)"></con>
				</div>
			</div>
	</div>
</template>

<script>
	import axios from 'axios'
	import con from 'base/content/content'
	let partitionList=window.__INITIAL_STATE__.reduxAsyncConnect.partitionList
	export default {
		props:{
			tid:{
				type:[String,Number],
				default:"1"
			},
			
		},
		created(){
			if(this.$route.path.indexOf("channel")!=-1){
				this._initTid()
				this._initSecon()
			}
		},
		components:{
			con
		},
		data(){
			return {
				secondNavList:[],
				NavList:[],
				curTid:"1",
				Secon:[],
				showSecon:[]
			}
		},
		computed:{
			
		},
		methods:{
			_handleCon(arr){
					return arr.filter((item,index)=>{return index<4})
		
			},
			_initTid(){
				this.curTid=this.$store.getters.getCurTid
				this.secondNavList=partitionList[this.$store.getters.getCurTid]
			},
			_initSecon(){
				let tmpArr=[];
				this.Secon=[];
				
				let firstObj={
					title:"热门推荐",
					rid:this.curTid,
					day:7
				}
				tmpArr.push(firstObj);
				//组装数据
				this.secondNavList.forEach((el)=>{
					let tmpObj=Object.assign({},{
						title:el.typename,
						rid:el.tid,
						day:this.curTid==1?3:7,
					})
					tmpArr.push(tmpObj)
				})
				//请求数据
				
				tmpArr.forEach((el,index)=>{
					axios.get('/get/region',{
					params:{
						"rid":el.rid,
						"day":el.day,
						"jsonp":"jsonp"
					}
				})
					.then((res)=>{
						el.con=res.data.data
//						this.Secon=[];
						this.Secon.push(el)
					})
				})
				//组装数据
			}
		},
		watch:{
//			$route(newValue){
//				this.$emit("PchangeTid",newValue.params.tid)
//			},
			tid(newValue){
//				实时更新NavList的内容
				if(this.$route.fullPath.indexOf("channel")!=-1){
					this._initTid()
					this._initSecon()
				}
			}
		}
	}
</script>

<style lang="scss" type="text/css" scoped>
	@import "~@/common/scss/common";
	.secNavWrap{
		background: $bgcF9;
		height: 30px;
		overflow: hidden;
	}
	.secNav{
		font-size:0;
		white-space: nowrap;
		overflow-x:scroll ;
		-webkit-overflow-scrolling: touch;
		padding-left: 18px;
		padding-bottom: 10px;
		a{
			display:inline-block;
			color:$fontcolor;
			font-size:14px;
			line-height: 36px;
			margin-right:16px;
		}
		.router-link-exact-active{
			color: $maincolor;
			
		}
	}
</style>